package m.store.action;

import m.base.action.BaseAction;
import m.base.util.LevelUtil;
import m.base.util.PowerUtil;
import m.common.action.ActionMeta;
import m.common.action.VueResult;
import m.common.model.util.QueryCondition;
import m.html.VueListResult;
import m.html.list.EventType;
import m.html.list.ListCount;
import m.html.list.ListEvent;
import m.store.model.OrderModel;
import m.store.model.PayAmountRecord;
import m.system.exception.MException;
import m.system.util.StringUtil;

@ActionMeta(name = "store/payAmountRecord")
public class PayAmountRecordAction extends BaseAction {

    /*
     * 入库订单
     */
    public VueResult recordList() throws Exception {
        VueListResult result=getVueListResult("入库订单", PayAmountRecord.class,actionUrl("recordList"));
        result.setFunction(LevelUtil.exportFunc(),false);
        result.setHeight(-1);
        result.addCol(toIndexColumn());
        if(StringUtil.notSpace(getParamsValue("pay.oid"))) {
            result.addCondition(QueryCondition.eq("pay.oid",getParamsValue("pay.oid")));
        }else if(StringUtil.notSpace(getParamsValue("guestOid"))){
            result.hideHead();
            result.addCol(toLinkColumn("付款单号", "pay.orderNo", 100, true,
                new ListEvent(actionUrl(PayAmountAction.class,"toView"), EventType.MODAL,1200)
                    .addParam("model.oid","pay.oid")
            ));
            result.addCol(toDateColumn("付款时间", "pay.payDate", 100, true));
            result.addCondition(QueryCondition.eq("pay.guest.oid", getParamsValue("guestOid")));
            result.addCondition(QueryCondition.eq("pay.status", OrderModel.Status_Done));
        }else{
            throw new MException(this.getClass(),"参数错误");
        }
        result.addCol(toLinkColumn("入库单号", "stock.orderNo", 100, true,
            new ListEvent(actionUrl(StockInfoAction.class,"toView"), EventType.MODAL,1200)
                .addParam("model.oid","stock.oid")
        ));
        result.addCol(toDateColumn("入库日期", "stock.stockDate", 100, true));
        result.addCol(toNumberColumn("入库金额", "stock.stockAmount", 100, true).setCount(ListCount.NONE));
        result.addCol(toNumberColumn("付款金额", "payAmount", 100, true));
        result.addCol(toTextColumn("备注", "remark", 150, true));
        //排序 result.addOrder
        //查询条件 result.addCondition
        result.addCondition(QueryCondition.eq("pay.store.oid", PowerUtil.getSessionStoreOid()));
        return result;
    }
}
